goog.require('dk.BookEditor');

goog.require('gdata.auth.ServiceName');
goog.require('gdata.auth.User');

goog.require('goog.dom');
goog.require('goog.ui.Control');
goog.require('goog.ui.ControlRenderer');
goog.require('goog.ui.ToggleButton');
goog.require('goog.ui.registry');


// Set up some UI decorators specific to this application.
var buttonClass = goog.getCssName('dk-button');
var buttonRenderer = goog.ui.ControlRenderer.getCustomRenderer(
    goog.ui.ControlRenderer, buttonClass);
goog.ui.registry.setDecoratorByClassName(buttonClass, function() {
  return new goog.ui.Control(null /* content */, buttonRenderer);  
});

var toggleButtonClass = goog.getCssName('dk-toggle-button');
var toggleButtonRenderer = goog.ui.ControlRenderer.getCustomRenderer(
    goog.ui.ControlRenderer, toggleButtonClass);
goog.ui.registry.setDecoratorByClassName(toggleButtonClass, function() {
  return new goog.ui.ToggleButton(null /* content */, toggleButtonRenderer);  
});

goog.exportSymbol('initEditor', function(email, authToken, logoutUrl, documentIds) {
  gdata.auth.writeAuthToken(gdata.auth.ServiceName.DOCUMENTS_LIST, authToken);
  var user = new gdata.auth.User(email);
  var dom = goog.dom.getDomHelper(document);
  var bookEditor = new dk.BookEditor(user, logoutUrl, documentIds, dom);
  bookEditor.decorate(document.body);
});
